﻿using Model.Extend;
using Model.sys;
using System.Text;

namespace CToolsWin.DAL.sys
{
    public class DALDirectoryInfo: IDAL.BaseModelADO<sys_DirectoryInfo>
    {
        /// <summary>
        /// 初始化表
        /// </summary>
        public bool InitTable()
        {
            return DBInit.TruncateTable(ModelAttribute.GetTableName<sys_DirectoryInfo>());
        }
        public bool IsExists(sys_DirectoryInfo m)
        {
            StringBuilder sql = new StringBuilder();
            if (m.ID > 0)
            {
                sql.Append(" AND [ID]<>@ID");
            }
            if (string.IsNullOrWhiteSpace(m.FullName) == false)
            {
                sql.AppendFormat(" AND FullName='{0}'", m.FullName);
            }
            return db.Exists(ModelAttribute.GetTableName<sys_DirectoryInfo>(), sql.ToString(), DB.ADOHelper.SetParmValues(m, m.ID > 0));
        }
        public sys_DirectoryInfo GetModel(sys_DirectoryInfo m)
        {
            StringBuilder sql = new StringBuilder();
            if (m.ID > 0)
            {
                sql.Append(" AND [ID]<>@ID");
            }
            if (string.IsNullOrWhiteSpace(m.FullName) == false)
            {
                sql.AppendFormat(" AND FullName='{0}'", m.FullName);
            }

            if (string.IsNullOrEmpty(sql.ToString()))
                sql.Append(" AND 1=2 ");
            return db.GetModelText<sys_DirectoryInfo>(sql.ToString(), DB.ADOHelper.SetParmValues(m, m.ID > 0));
        }
    }
}
